package jUnitTestSuite;

import org.junit.Before;
import org.junit.Test;
import junit.framework.TestCase;

public class ProductTestCase extends TestCase
{
	private Product p;
	
	@Before
	protected void setUp() throws Exception
	{
		p = new Product( "test product", 42 );
	}

	@Test // test increase price
	public void testIncreasePrice()
	{
		// add 5 to the value of the price
		// should get 47
		p.increasePrice( 5 );
		assertEquals( 47.00 , p.getPrice() );
	}
	
	@Test // test decrease price
	public void testDecreasePrice()
	{
		// decrease price by 10, should get 32
		p.decreasePrice( 10 );
		assertEquals( 32.00, p.getPrice() );
	}
	
	@Test // test toString
	public void testToString()
	{
		// test the output string format
		assertEquals( "Product: test product Price: $42.0", p.toString() );
	}
	
	@Test // test get/set
	public void testGetSet()
	{
		// ensure getters and setters work
		p.setName( "new name");
		p.setPrice( 56 );
		assertEquals( "new name", p.getName() );
		assertEquals( 56.0, p.getPrice() );
	}
	
	// main method
	public static void main( String args[] )
	{
		// run the test
		junit.textui.TestRunner.run( ProductTestCase.class );
		
	}
}
